package com.xxgc.helloworld.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.w3c.dom.DocumentType;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //是否开启前端ui显示 生产环境调为false
                .enable(true)
                .select()
                //扫描有哪些接口（controller）要生成文档
                .apis(RequestHandlerSelectors.basePackage("com.xxgc.helloworld.controller"))
                //接口中所有路径都扫描
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                //api文档标题
                .title("HelloWorld工程")
                //文档描述
                .description("工程文档描述")
                //服务条款url
                .termsOfServiceUrl("https://www.baidu.com")
                //版本号
                .version("1.0.0")
                .build();
    }
}
